package cn.dylan.controller;

import cn.dylan.block.blockMethod;
import cn.dylan.domain.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
@RefreshScope
public class UserController {

    @Value("${test.name}")
    private String name;

    @GetMapping("/getById/{id}")
    @SentinelResource(value = "user-service-getById", blockHandler = "block", blockHandlerClass = blockMethod.class)
    public User getUser(@PathVariable("id") Long id){
        return new User(id,"伦丁影视","只做用户想看的"+name);
    }

    /*public User blockMethod(@PathVariable("id") Long id, BlockException e){
        e.printStackTrace();
        return new User(-1L,"不得行了","做不了你想看的了"+name);
    }*/
}
